package com.rr.program._stopWatch;

import org.springframework.util.StopWatch;

import java.util.concurrent.TimeUnit;

/**
 * java StopWatch 输出程序的运行时间
 *
 * @author : RENBIAO
 * @createTime : 2022/1/14 11:20
 */
public class StopWatchTest {


    public static void main(String[] args) {

        //开始时间
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("任务1");

        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (Exception e) {
            e.printStackTrace();
        }

        stopWatch.stop();
        System.out.println(stopWatch.prettyPrint());

        stopWatch.start("任务2");

        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (Exception e) {
            e.printStackTrace();
        }

        stopWatch.stop();
        System.out.println(stopWatch.prettyPrint());

        stopWatch.start("任务3");

        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (Exception e) {
            e.printStackTrace();
        }

        stopWatch.stop();
        System.out.println(stopWatch.prettyPrint());
    }
}
